<template>
  <div class="login-container">
    <el-form :model="loginForm" :rules="loginRules" ref="loginForm" label-position="left" label-width="0px" class="login-form animated fadeInDown">
      <h2 class="title">幻熊科技后台</h2>
      <el-form-item prop="account">
        <el-input size="middle" type="text" v-model="loginForm.username" auto-complete="off" placeholder="账号"></el-input>
      </el-form-item>
      <el-form-item prop="checkPass">
        <el-input size="middle" type="password" v-model="loginForm.password" auto-complete="off" placeholder="密码"></el-input>
      </el-form-item>
      <!--<el-checkbox v-model="checked" checked class="remember">记住密码</el-checkbox>-->
      <el-form-item style="width:100%;">
        <el-button size="middle" type="primary" style="width:100%;" @click.native.prevent="handleSubmit2" :loading="logining">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
const isDev = process.env.NODE_ENV === 'development'

export default {
  name: 'login',

  data() {
    return {
      logining: false,
      loginForm: {
        username: isDev ? 'guansq' : '',
        password: isDev ? 111111 : ''
      },
      loginRules: {
        username: [{
          required: true, trigger: 'blur', message: '请输入账号'
        }],
        password: [{
          required: true, trigger: 'blur', message: '请输入密码'
        }]
      }
    };
  },
  methods: {
    handleReset2() {
      this.$refs.ruleForm2.resetFields();
    },
    handleSubmit2() {
      this.$refs.loginForm.validate(async (valid) => {
        if (valid) {
          this.$store.dispatch('login', this.loginForm).then(() => {
            this.$router.addRoutes(this.$store.state.permission.addRouters) // 动态添加可访问路由表
            this.$router.replace({ path: '/' })
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: url('./bg.svg') no-repeat center center;
  background-size: 100% auto;
}
.login-form {
  border-radius: 5px;
  width: 350px;
  padding: 35px 35px 15px 35px;
  background: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #eee;
  margin-bottom: 10%;
  .title {
    margin: 0 auto;
    text-align: center;
    color: #505458;
  }
  .remember {
    margin: 0 0 35px 0;
  }
}
</style>
